GoLang

Explain Identifiers in Go Language | Go Programming Tutorial

Explain Identifiers in Go Language | Go Programming Tutorial

Explain Identifiers in Go Language | Go Programming Tutorial

In this article, you will learn the following:

  • What are identifiers?
  • Rules for defining the identifiers

What are identifiers?

In programming languages, identifiers are used for identification purposes. In simple words, identifiers are the user-defined name of the program components. In the Go language, an identifier can be anything such as a variable name, function name, constant, statement labels, types, or package name. 

Example:

  package main

  import “fmt”

  Func main() {

       var name = “GeeksforGeeks”

  }

There is total of three identifiers in the above example:

  • main: Name of the package
  • main: Name of the function
  • name: Name of the variable

Rules for defining Identifiers: There are certain valid rules which are used in defining a valid Go identifier. These rules should be followed, otherwise, the user will get a compile-time error.

  • The name of the identifier has to begin with a letter or an underscore(_). It can contain the letters ‘a-z’ or ‘A-Z’ or digits 0-9.
  • The name should not be started with any digit.
  • The name of the identifier should be case-sensitive.
  • Keywords can be used as an identifier.
  • There is no limit on the length of the identifier.

Note:

  • In the Go language, there are some predeclared identifiers available for constants, types, and functions. These names do not fall under the category of reserved identifiers, you can use them in the declaration.
  • The identifiers represented using the underscore character are known as blank identifiers.
  • The identifier which allows access to it from another package is called the exported identifier. These identifiers should obey the following conditions:
    • The first character should be in the Unicode uppercase letter
    • It needs to be declared in the package block, or it is a variable name, or it is a method.
  • The uniqueness of the identifiers means the name of the identifier has to be unique from the other set of identifiers available in the program or the package.
Yamini  Sharma

I am working as a professional engineer in "HIghRadius Technologies Pvt. Ltd." Passionate about learning and exploring new technologies. Enthusiast in writing and sharing what I have in my knowledge bucket.